/*
 * @Author: your name
 * @Date: 2020-05-20 19:53:22
 * @LastEditTime: 2021-10-07 00:44:29
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \generallib\general\src\pattern\adapter.hpp
 */
//
// Created by 29019 on 2019/12/30.
//
#ifndef GENERAL_ADAPTER_H
#define GENERAL_ADAPTER_H

#include <string>
#include <map>
template <typename  T>
class Adapter{
    T mAdapter;
};
template <typename  T>
class Adaptee{

};

template<typename  T>
class Bridgeable{
public:
    Bridgeable(){

    }
    Bridgeable(T *dat){
        mBridgeData = dat;
    }

protected:
    T *mBridgeData;

};
template <typename  T>
class ResponsabilityChan{
public:
    int AddNext(ResponsabilityChan *p){

    }
private:
    ResponsabilityChan *mHead;
    ResponsabilityChan *mTail;
};
template<typename  T>
class Mediator;
template<typename  T>
class MediatorColleague{
public:
    std::string GetName(){
        return mName;
    };
    int SetMediater(Mediator<T>* p){
        mMediater = p;
        return 0;
    }
    virtual int Send(std::string colleage,T data)=0;
    virtual int Recv(std::string colleage,T data)=0;
protected:
    std::string mName;
    Mediator<T> *mMediater;

    MediatorColleague(std::string name,Mediator<T> *p){
        mName = name;
        mMediater = p;
    }
private:
    MediatorColleague(){
    }
};
template <typename  T>
class Mediator{
public:
    int Register(MediatorColleague<T> *p){ // 注册
        if (nullptr == p){
            return -1;
        }
        if(mColleague.find(p->GetName()) != mColleague.end()){
            return -1;
        }
        mColleague[p->GetName()] = p;
        p->SetMediater(this);
        return -1;
    }
    int Relay(std::string colleage,T data){ //转发
        if(mColleague.find(colleage) != mColleague.end()){
            MediatorColleague<T> *recvcolleage = mColleague.find(colleage)->second;
            recvcolleage->Recv("",data);
        }
        return -1;
    }
private:
    std::map<std::string,MediatorColleague<T>*> mColleague;
};

#endif //GENERAL_ADAPTER_H
